package com.danieldura.highrise.requests
{
	import com.danieldura.highrise.HighriseCredentials;
	import com.danieldura.highrise.data.Company;
	
	import flash.net.URLRequestMethod;
	
	public class CompaniesRequest extends HighriseRequest
	{
		
		public function CompaniesRequest( credentials:HighriseCredentials )
		{
			super( credentials, new HighriseRequestDataMap( "company", "companies", Company ) );
		}
		
		public function show( id:int ):void
		{
			requestMethod = URLRequestMethod.GET;
			location = "/companies/" + id + format;
			send();			
		}
		
		public function listAll( offset:int ):void
		{
			requestMethod = URLRequestMethod.GET;
			location = "/companies" + format + "?n=" + offset;
			send();				
		}
		
		public function listWithTag( tagId:int, offset:int ):void
		{
			requestMethod = URLRequestMethod.GET;
			location = "/companies" + format + "?tag_id=" + tagId + "&n=" + offset;
			send();
		}
		
		public function listBySearchTerm( searchTerm:String, offset:int ):void
		{
			requestMethod = URLRequestMethod.GET;
			location = "/companies" + format + "?term=" + escape(searchTerm) + "&n=" + offset;
			send();
		}
		
		public function listSinceTime( dateTime:Date, offset:int ):void
		{
			requestMethod = URLRequestMethod.GET;
			location = "/companies" + format + "?since=" + encodeDate( dateTime ) + "&n=" + offset;
			send();
		}
		
		public function create( company:Company ):void
		{
			requestMethod = URLRequestMethod.POST;
			location = "/companies.xml";
			requestData = company.toXMLString();
			send();
		}
		
		public function udpate( company:Company ):void
		{
			requestMethod = "PUT";
			location = "/companies/" + company.id + ".xml";
			requestData = company.toXMLString();
			send();
		}
		
		public function destroy( company:Company ):void
		{
			requestMethod = "DELETE";
			location = "/companies/" + company.id + ".xml";
			send();
		}
		
	}
}